package org.huntaway.kernel.imp;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.huntaway.kernel.NutException;
import org.huntaway.kernel.TimesTools;

public class TimesToolsImp implements TimesTools {
	public static final String SIMPLE_DATE_FORMAT_24_SHORT = "yyyy-MM-dd";
	public static final String SIMPLE_DATE_FORMAT_24 = "yyyy-MM-dd HH:mm:ss";
	public static final String STY_24 = SIMPLE_DATE_FORMAT_24;
	SimpleDateFormat daSty_24 = new SimpleDateFormat(STY_24);

	/**
	 * @param str
	 * @param dateStyle
	 * @return
	 * @throws RadException
	 */
	public Date str2Time(String str, String dateStyle) throws NutException {
		SimpleDateFormat daSty = new SimpleDateFormat(dateStyle);
		try {
			return daSty.parse(str);
		} catch (ParseException e) {
			throw new NutException(e);
		}
	}

	/**
	 * @param date
	 * @param dateStyle
	 * @return
	 * @throws RadException
	 */
	public String Time2Str(Date date, String dateStyle) {
		SimpleDateFormat daSty = new SimpleDateFormat(dateStyle);
		return daSty.format(date);
	}

	/**
	 * @param dateStyle
	 * @return
	 */
	public String nowDate(String dateStyle) {
		SimpleDateFormat daSty = new SimpleDateFormat(dateStyle);
		return daSty.format(new Date());
	}

	public String getDate(long times) {
		return daSty_24.format(new Date(times));
	}
}
